#ifndef LIST_H
#define LIST_H

#include <stdbool.h>

typedef struct list
{
	void *pbuffer;
	unsigned int unit;
	unsigned int length;
    unsigned int size;
}list;

#define list_length(l)      		(l)->length
#define list_reset(l)       		(l)->length = 0
#define list_is_empty(l)    		(l)->length==0
#define list_is_full(l)     		(l)->length*(l)->unit>=(l)->size
#define list_push(l,e)      		list_insert(l,list_length(l),e)
#define list_pop(l,e)       		list_remove(l,list_length(l),e)
#define list_enque(l,e)     		list_insert(l,list_length(l),e)
#define list_deque(l,e)     		list_remove(l,0,e)
#define list_append(l,e)    		list_insert(l,list_length(l),e)


void list_create(list *l,unsigned int unit,unsigned int length_in_unit);
void list_destroy(list *l);
bool list_get(list *l,unsigned int index,void *e);
bool list_set(list *l,unsigned int index,void *e);
bool list_insert(list *l,unsigned int index,void *e);
bool list_remove(list *l,unsigned int index,void *e);
unsigned int list_find(list *l,unsigned int index,void *e);
void list_traverse(list *l,bool (*visit)(void *));


#endif /* LIST_H */
